package com.canbot.u05.activity.agenda.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import android.widget.TextView
import com.canbot.u05.R
import kotlinx.android.synthetic.main.layout_agenda_create_item.view.*

/**
 * @author yinxiaowei
 * @date 2019/5/31
 */
class AgendaItemCreateView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = -1) : RelativeLayout(context, attrs, defStyleAttr) {
    private lateinit var tvTitle: TextView
    private lateinit var tvData: TextView

    init {
        initView()
        initStyle(context, attrs)
    }

    private fun initStyle(context: Context, attrs: AttributeSet?) {
        val typedArray = context.obtainStyledAttributes(attrs, R.styleable.AgendaItemCreateView)
        val resourceTitle = typedArray.getResourceId(R.styleable.AgendaItemCreateView_itemTitle, -1)
        val resourceData = typedArray.getResourceId(R.styleable.AgendaItemCreateView_itemData, -1)
        tvTitle.text = context.getString(resourceTitle)
        if (resourceData != -1) {
            tvData.text = context.getString(resourceData)
        }
        typedArray.recycle()
    }

    private fun initView() {
        val view = LayoutInflater.from(context).inflate(R.layout.layout_agenda_create_item, this)
        tvTitle = view.tvTitle
        tvData = view.tvData
    }

    fun updateText(data: String) {
        tvData.text = data
    }

    fun updateTitle(data: String) {
        tvTitle.text = data
    }
}
